package com.nd.teamfile.fileexplorer.helper;

import com.nd.teamfile.fileexplorer.sdk.type.MediaFile;


/**
 * 文件类别管理类
 * 
 * @ClassName FileCategoryHelper
 * @Function TODO ADD FUNCTION
 * @Reason TODO ADD REASON
 * 
 * @author HuangYK
 * @version v1.3.3
 * @Date 2014-1-24 上午1:56:35
 * 
 * @see
 */
public class FileCategoryHelper {
	public enum FileCategory {
		All, Music, Video, Picture, Apk, Other, PSD
	}

	private static String APK_EXT = "apk";

	/**
	 * 通过路径获取文件类型
	 * 
	 * @n<b>函数名称</b> :getCategoryFromPath
	 * @brief
	 * @see
	 * @version Ver 1.3.3
	 * @param @param path
	 * @param @return
	 * @return FileCategory
	 * @<b>作者</b> : HuangYK
	 * @<b>创建时间</b> : 2014-1-24下午2:26:29
	 */
	public static FileCategory getCategoryFromPath(String path) {
		int type = MediaFile.getFileType(path);
		if (type != -1) {
			if (MediaFile.isVideoFileType(type))
				return FileCategory.Video;
			if (MediaFile.isImageFileType(type))
				return FileCategory.Picture;
		}
		int dotPosition = path.lastIndexOf('.');
		if (dotPosition < 0) {
			return FileCategory.Other;
		}

		String ext = path.substring(dotPosition + 1);
		if (ext.equalsIgnoreCase(APK_EXT)) {
			return FileCategory.Apk;
		}

		return FileCategory.Other;
	}
}
